<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use DB;
use App\Models\Squad;
use App\Models\Crouse;
use App\Models\Classroom;
use App\Models\Notice;


class Report extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'Report';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $squads = Squad::all()->toArray();

        foreach($squads as $v){
            $students = DB::table('students')->where('squad_id',$v['id'])->where('status','1')->get();
            $temp = array();
            $temp['pid'] = 0;
            $temp['name'] = $v['name'].'-3月成长报告';
            $temp['section'] = $v['section'];
            $temp['group'] = $v['group'];
            $temp['squad'] = $v['id'];
            $temp['student'] = 0;
            $temp['type'] = '1,2,3,4,5';
            $temp['start_time'] = '2019-02-18';
            $temp['end_time'] = '2019-04-07';
            $temp['operator'] = $v['class_teacher'];

            $id = DB::table('reports')->insertGetId($temp);
            $insert = array();
            foreach($students as $_v){
                $insert[] = array(
                    'pid'=>$id,
                    'student'=>$_v->id,
                    'name'=>$_v->no.'-'.$_v->en_name.'-'.$_v->ch_name
                );
            }
            DB::table('reports')->insert($insert);
        }
    }
}
